<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>0</div>
<script>
  let count = 0;
  let d = document.querySelector("div");
  //开启定时器 每隔0.1秒调用匿名方法
  let timer = setInterval(function () {
    count++;
    d.innerText = count;
    if (count==50){
      //停止定时器
      clearInterval(timer);
    }
  },100);

  //开启只执行一次的定时器
  setTimeout(function () {
    console.log("时间到!")
  },3000);
</script>
</body>
</html>